﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace VisionCloud.Core.Migrations
{
    public partial class AlterMsReport : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysUserRole_SysUser_UserId",
                table: "SysUserRole");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysUser",
                table: "SysUser");

            migrationBuilder.DropIndex(
                name: "IX_MsReport_TaskReportId",
                table: "MsReport");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysDeviceUser",
                table: "SysDeviceUser");

            migrationBuilder.DropColumn(
                name: "UserId",
                table: "SysUser");

            migrationBuilder.DropColumn(
                name: "Code",
                table: "SysUser");

            migrationBuilder.RenameTable(
                name: "SysDeviceUser",
                newName: "SysDeviceUsers");

            migrationBuilder.RenameColumn(
                name: "LastUpdatedDate",
                table: "SysUser",
                newName: "UpdateDateTime");

            migrationBuilder.RenameColumn(
                name: "LastUpdatedBy",
                table: "SysUser",
                newName: "UpdateUserGuid");

            migrationBuilder.RenameColumn(
                name: "CreatedDate",
                table: "SysUser",
                newName: "CreateDateTime");

            migrationBuilder.RenameColumn(
                name: "CreatedBy",
                table: "SysUser",
                newName: "CreateUserGuid");

            migrationBuilder.RenameIndex(
                name: "IX_SysDeviceUser_UserGuid",
                table: "SysDeviceUsers",
                newName: "IX_SysDeviceUsers_UserGuid");

            migrationBuilder.RenameIndex(
                name: "IX_SysDeviceUser_DeviceGuid",
                table: "SysDeviceUsers",
                newName: "IX_SysDeviceUsers_DeviceGuid");

            migrationBuilder.AlterColumn<int>(
                name: "UserType",
                table: "SysUser",
                type: "int4",
                nullable: true,
                oldClrType: typeof(int));

            migrationBuilder.AlterColumn<int>(
                name: "Status",
                table: "SysUser",
                type: "int4",
                nullable: false,
                oldClrType: typeof(int));

            migrationBuilder.AlterColumn<int>(
                name: "IsLocked",
                table: "SysUser",
                type: "int4",
                nullable: false,
                oldClrType: typeof(bool));

            migrationBuilder.AlterColumn<string>(
                name: "AccountNumber",
                table: "SysUser",
                type: "varchar(32)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "varchar(50)",
                oldNullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "YunUserGuid",
                table: "SysUser",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AlterColumn<bool>(
                name: "IsNew",
                table: "MsReport",
                nullable: false,
                oldClrType: typeof(bool),
                oldType: "bool");

            migrationBuilder.AddColumn<DateTime>(
                name: "CreateReportDateTime",
                table: "MsReport",
                type: "timestamp(0)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<int>(
                name: "TaskType",
                table: "MsReport",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysUser",
                table: "SysUser",
                column: "YunUserGuid");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysDeviceUsers",
                table: "SysDeviceUsers",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_TaskReportId",
                table: "MsReport",
                column: "TaskReportId",
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_SysUserRole_SysUser_UserId",
                table: "SysUserRole",
                column: "UserId",
                principalTable: "SysUser",
                principalColumn: "YunUserGuid",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysUserRole_SysUser_UserId",
                table: "SysUserRole");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysUser",
                table: "SysUser");

            migrationBuilder.DropIndex(
                name: "IX_MsReport_TaskReportId",
                table: "MsReport");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysDeviceUsers",
                table: "SysDeviceUsers");

            migrationBuilder.DropColumn(
                name: "YunUserGuid",
                table: "SysUser");

            migrationBuilder.DropColumn(
                name: "CreateReportDateTime",
                table: "MsReport");

            migrationBuilder.DropColumn(
                name: "TaskType",
                table: "MsReport");

            migrationBuilder.RenameTable(
                name: "SysDeviceUsers",
                newName: "SysDeviceUser");

            migrationBuilder.RenameColumn(
                name: "UpdateUserGuid",
                table: "SysUser",
                newName: "LastUpdatedBy");

            migrationBuilder.RenameColumn(
                name: "UpdateDateTime",
                table: "SysUser",
                newName: "LastUpdatedDate");

            migrationBuilder.RenameColumn(
                name: "CreateUserGuid",
                table: "SysUser",
                newName: "CreatedBy");

            migrationBuilder.RenameColumn(
                name: "CreateDateTime",
                table: "SysUser",
                newName: "CreatedDate");

            migrationBuilder.RenameIndex(
                name: "IX_SysDeviceUsers_UserGuid",
                table: "SysDeviceUser",
                newName: "IX_SysDeviceUser_UserGuid");

            migrationBuilder.RenameIndex(
                name: "IX_SysDeviceUsers_DeviceGuid",
                table: "SysDeviceUser",
                newName: "IX_SysDeviceUser_DeviceGuid");

            migrationBuilder.AlterColumn<int>(
                name: "UserType",
                table: "SysUser",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int4",
                oldNullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "Status",
                table: "SysUser",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int4");

            migrationBuilder.AlterColumn<bool>(
                name: "IsLocked",
                table: "SysUser",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int4");

            migrationBuilder.AlterColumn<string>(
                name: "AccountNumber",
                table: "SysUser",
                type: "varchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "varchar(32)");

            migrationBuilder.AddColumn<Guid>(
                name: "UserId",
                table: "SysUser",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<string>(
                name: "Code",
                table: "SysUser",
                type: "varchar(32)",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AlterColumn<bool>(
                name: "IsNew",
                table: "MsReport",
                type: "bool",
                nullable: false,
                oldClrType: typeof(bool));

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysUser",
                table: "SysUser",
                column: "UserId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysDeviceUser",
                table: "SysDeviceUser",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_TaskReportId",
                table: "MsReport",
                column: "TaskReportId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysUserRole_SysUser_UserId",
                table: "SysUserRole",
                column: "UserId",
                principalTable: "SysUser",
                principalColumn: "UserId",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
